package com.riber.lession67.web.servlet;

import com.riber.lession67.common.Const;
import com.riber.lession67.entity.Emp;
import com.riber.lession67.services.EmpServices;
import com.riber.lession67.services.impl.EmpServicesImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author: Riber
 * @date: 2022/09/21 23:04
 * @description:
 */
@WebServlet("/emp")
public class EmpController extends BaseServlet {
    private EmpServices es = new EmpServicesImpl();

    public String doLogin(HttpServletRequest request, HttpServletResponse response) {

        String ename = request.getParameter("ename");
        String pwd = request.getParameter("pwd");

        Emp emp = es.doLogin(ename, pwd);

        if (emp != null) {
            request.getSession().setAttribute("is_login", emp);
            return Const.REDIRECT + "/index.jsp";
        } else {
            return Const.REDIRECT + "/login.jsp";
        }
    }
}
